<?php

/*
 * We try to know if is better store an interger indexed array or string indexed array
 */

$test0 = array( 0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd', 9 => 'e', 15 => 'f', 21 => 'g',
    24 => 'd' );
$test1 = array_flip( $test0 );
$i = 0;
$s0 = array( );

file_put_contents( 'test0.serialization0', serialize( $test0 ) );
file_put_contents( 'test0.serialization1', serialize( $test1 ) );


$t0 = microtime( true );
for ( $i = 0; $i < 100000; $i++ ) {
    $s0 = unserialize( file_get_contents( 'test0.serialization0' ) );
    //  $s1=array_flip($s0);
}
$t1 = microtime( true );
for ( $i = 0; $i < 100000; $i++ ) {
    $s0 = unserialize( file_get_contents( 'test0.serialization1' ) );
//    $s1=array_flip($s0);
}
$t2 = microtime( true );


echo ($t1 - $t0) . "\n";
echo ($t2 - $t1) . "\n";

/*
 *  without array_flip
  svrhou021:/mnt/filesystem/mate_wwwssl# /usr/bin/php5 ./prueba0_serialization.php
  1.99997806549
  1.94261884689
  svrhou021:/mnt/filesystem/mate_wwwssl# /usr/bin/php5 ./prueba0_serialization.php
  1.98253893852
  1.9635488987
 */


/*
 * with array_flip
  svrhou021:/mnt/filesystem/mate_wwwssl# /usr/bin/php5 ./prueba0_serialization.php
  2.41799998283
  2.40795516968
  svrhou021:/mnt/filesystem/mate_wwwssl# /usr/bin/php5 ./prueba0_serialization.php
  2.4104411602
  2.3832218647
 */
?>
